package utstat;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class UtEventListenerRunner implements Runnable {

    private BlockingQueue<UtEvent> eventQueue = new LinkedBlockingQueue<UtEvent>();

    private UtEventListener listener;

    public UtEventListenerRunner(UtEventListener listener) {
        this.listener = listener;
    }

    public void enqueueEvent(UtEvent ute) {
        try {
            eventQueue.put(ute);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        while (true) {
            try {
                listener.processEvent(eventQueue.take());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
